package org.ws.lifebacklog.activity;

import org.ws.lifebacklog.adapter.GenericAdapter;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class GenericListActivity<T> extends GenericActivity {

	private ListView list;
	private GenericAdapter<T> adapter;

	/** {@inheritDoc} */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	private AdapterView.OnItemClickListener onListViewClickListener = new AdapterView.OnItemClickListener() {
		public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
			onListItemClick((ListView) parent, v, position, id);
		}
	};

	@Override
	public void onContentChanged() {
		super.onContentChanged();
		list = (ListView) findViewById(android.R.id.list);
		list.setOnItemClickListener(onListViewClickListener);
	}

	public void setListAdapter(GenericAdapter<T> adapter) {
		synchronized (this) {
			this.adapter = adapter;
			list.setAdapter(adapter);
		}
	}

	public GenericAdapter<T> getListAdapter() {
		return adapter;
	}

	public ListView getListView() {
		return list;
	}

	protected void onListItemClick(ListView l, View v, int position, long id) {
	}
}
